<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    var successfullPairs = function (spells, potions, success) {
      let ans = potions.map(el => Math.ceil(success / el)).sort((a, b) => a - b)
      let book = []
      let k = 0
      let count = 0
      for (var i = 1; i < 100000; i++) {
        while (i === ans[k]) {
          // book[k] 用来记录 <= i 有几个数
          book[i] = ++count
          k++
        }
        book[i] = count
      }
      let res = []
      for (let i = 0; i < spells.length; i++) {
        res[i] = book[spells[i]]
      }
      return res
    }
    console.log(successfullPairs(spells = [5, 1, 3], potions = [1, 2, 3, 4, 5], success = 7))
  </script>
</body>

</html>